﻿#ifndef VIDEOWINDOW_H
#define VIDEOWINDOW_H

#include <QWidget>

class QMenu;
class ZoomVideoWidget;

class VideoWindow : public QWidget
{
    Q_OBJECT
public:
    explicit VideoWindow(QWidget *parent = Q_NULLPTR);
    QSize sizeHint() const;
    QSize minimumSizeHint() const;

    bool tryAcceptDrop(QDropEvent *eFromParent);
    bool tryContextMenu(QContextMenuEvent *eFromParent, QWidget *grandParent);
    bool isOn() const;

    void setId(int micid, qint64 uid, const QString &name = QString());

    void handleVideo(const QPixmap &pix);
    void handle_volume(int volume);
    void handle_timer_event();

    QPixmap videoPixmap;
    QSize videoSize;
    int id;
    qint64 uid;
    QString uname;
    quint8 rotate;
protected:
    void paintEvent(QPaintEvent * e);
    void resizeEvent(QResizeEvent *e);
    void enterEvent(QEvent *e);
    void leaveEvent(QEvent *e);
    void mouseMoveEvent(QMouseEvent * event);
    void mousePressEvent(QMouseEvent * event);
    void mouseDoubleClickEvent(QMouseEvent *event);
    virtual void setToolBarVisible(bool visible);
private slots:
    void clockwiseRotate();
    void anticlockwiseRotate();
    void resetRotate();
    void slot_zoomVideo_destroyed();
private:
    void stopVideoTimer(bool update = false);
    void stopAudioTimer();
    inline void updateVideoRect();
    inline void drawBackground(QPainter &paint, bool on);

    ZoomVideoWidget &getZoomVideo();
    ZoomVideoWidget *zoom;
    QWidget *toolBar;

    //QRect volumeRect;

    int video_timer_count;
    int audio_timer_count;
    int volume_;

    QPoint dragStartPosition;
protected:
    QRect videoRect;
    QRect bottomRect;
};

#endif // VIDEOWINDOW_H
